/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.ContentField;
import com.blandware.atleap.model.core.Localizable;

import java.util.List;

/**
 * <p>DAO for content field.</p>
 * <p><a href="ContentFieldDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.11 $ $Date: 2007/04/03 19:27:20 $
 */
public interface ContentFieldDAO extends DAO {

	// ~ CRUD Methods ================================================================

	/**
	 * Creates new localizable field
	 *
	 * @param field       Value object that represents what field must be created
	 * @param localizable Localizable to associate field with
	 * @return ID of created localizable field
	 */
	public Long createContentField(ContentField field, Localizable localizable);

	/**
	 * Retrieves localizable field with specified ID
	 *
	 * @param contentFieldId ID to search by
	 * @return Localizable field or null if no field with specified ID exists in database
	 */
	public ContentField retrieveContentField(Long contentFieldId);

	/**
	 * Updates localizable field
	 *
	 * @param contentField Localizable field to update
     * @param localizable Localizable to associate field with
	 */
	public void updateContentField(ContentField contentField, Localizable localizable);

	/**
	 * Deletes localizable field
	 *
	 * @param contentField field to delete
	 */
	public void deleteContentField(ContentField contentField);

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of localizable fields.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of fields
	 */
	public PartialCollection listContentFields(QueryInfo queryInfo);

	/**
	 * Searches for duplicates. Returns true if there is one or more fields with another ID, but which
	 * have same values from some set (e.g. identifier and localizable)
	 *
	 * @param contentField Field to find duplicates for
	 * @param ownerId      ID of owner Localizable
	 * @return whether this content field has duplicates
	 */
	public boolean hasDuplicates(ContentField contentField, Long ownerId);

	// ~ Finders ================================================================

	/**
	 * Finds localizable field by identifier and layout definition
	 *
	 * @param identifier Identifier of field to search by
	 * @param definition Struts tile definition on which localizable is based
	 * @return ContentField or null if nothing was found
	 */
	public ContentField findContentFieldByLayoutDefinition(String identifier, String definition);

	/**
	 * Finds indexed fields by identifier prefix and layout definition.
	 *
	 * @param identifier Identifier prefix of field to search by
	 * @param definition Struts tile definition on which localizable is based
	 * @return List of ContentFields or null if nothing was found
	 */
	public List findIndexedContentFieldsByLayoutDefinition(String identifier, String definition);

    /**
	 * Finds indexed fields by identifier prefix and layout definition.
     * Only those fields are returned that have a content field value for
     * specified locale or default locale.
	 *
	 * @param identifier Identifier prefix of field to search by
	 * @param definition Struts tile definition on which localizable is based
	 * @param locale     locale
	 * @return List of ContentFields or null if nothing was found
	 */
	public List findIndexedContentFieldsByLayoutDefinitionAndLocale(String identifier, String definition, String locale);

	/**
	 * Finds field by page URI and identifier
	 *
	 * @param identifier Identifier of field to search by
	 * @param uri        URI of page to which field belongs
	 * @return Page field or null if nothing was found
	 */
	public ContentField findContentFieldByPageUri(String identifier, String uri);

	/**
	 * Finds indexed fields by page URI and identifier prefix.
	 *
	 * @param identifier Identifier of field to search by
	 * @param uri        URI of page to which field belongs
	 * @return List of content fields or null if nothing was found
	 */
	public List findIndexedContentFieldsByPageUri(String identifier, String uri);

    /**
	 * Finds indexed fields by page URI and identifier prefix.
     * Only those fields are returned that have a content field value for
     * specified locale or default locale.
	 *
	 * @param identifier Identifier of field to search by
	 * @param uri        URI of page to which field belongs
	 * @param locale     locale
	 * @return List of content fields or null if nothing was found
	 */
	public List findIndexedContentFieldsByPageUriAndLocale(String identifier, String uri, String locale);

	/**
	 * Finds localizable field by identifier and localizable
	 *
	 * @param identifier  Identifier of field to search by
	 * @param localizable Owner of this field
	 * @return ContentField or null if nothing was found
	 */
	public ContentField findContentFieldByLocalizable(String identifier, Localizable localizable);


}
